using System;
using System.Collections.Generic;

namespace OracleInternal.SqlAndPlsqlParser
{
	[Serializable]
	internal abstract class RuleTupleBase<T> : IComparable<RuleTupleBase<T>>
	{
		protected int? m_vHashValue;

		public T m_vHead;

		public T[] m_vRhs;

		protected static int s_vNullHeadHashCode;

		private bool m_vIsUnary;

		protected static char[] s_vColonDelimiter = new char[1]
		{
			':'
		};

		protected static char[] s_vSpaceDelimiter = new char[1]
		{
			' '
		};

		protected static string[] s_vEmptyStringArray = new string[0];

		public T Head
		{
			get
			{
				return m_vHead;
			}
			set
			{
				m_vHead = value;
				m_vHashValue = null;
			}
		}

		public T[] RHS => m_vRhs;

		public bool IsUnary => m_vIsUnary;

		public RuleTupleBase(T h, List<T> r)
		{
			m_vHead = h;
			m_vRhs = r.ToArray();
			m_vIsUnary = m_vRhs.Length == 1;
		}

		public RuleTupleBase(T h, T[] r)
		{
			m_vHead = h;
			m_vRhs = r;
			m_vIsUnary = m_vRhs.Length == 1;
		}

		public RuleTupleBase()
		{
		}

		public override bool Equals(object obj)
		{
			if (this != obj)
			{
				return CompareTo(obj as RuleTupleBase<T>) == 0;
			}
			return true;
		}

		public override int GetHashCode()
		{
			if (!m_vHashValue.HasValue)
			{
				m_vHashValue = ((m_vHead != null) ? m_vHead.GetHashCode() : s_vNullHeadHashCode);
			}
			return m_vHashValue.Value;
		}

		public abstract int CompareTo(RuleTupleBase<T> src);
	}
}
